package org.example.caiwumanage.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.caiwumanage.entity.Budgetrecords;
import org.example.caiwumanage.entity.Query;
import org.example.caiwumanage.properties.BaseContext;
import org.example.caiwumanage.properties.JwtProperties;
import org.example.caiwumanage.result.Result;
import org.example.caiwumanage.service.TransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

/**
 * 员工管理
 */
@Slf4j
@RestController
@RequestMapping("/transaction")
public class TransactionController {

    @Autowired
    private TransactionService transactionService;
    @Autowired
    private JwtProperties jwtProperties;
    /**
     * 登录
     *
     * @return
     */

    @PostMapping()
    public Result create(@RequestBody Budgetrecords budgetrecords){
        log.info("创建新数据：{}", budgetrecords);
        System.out.println("当前线程"+Thread.currentThread().getId());
        transactionService.create(budgetrecords);
        return Result.success();
    }

    @DeleteMapping("/{budgetId}")
    public Result deltete(@PathVariable Integer budgetId ){
        log.info("删除数据id：{}",budgetId );
        transactionService.delete(budgetId);
        return Result.success();
    }

    @PutMapping()
    public Result update(@RequestBody Budgetrecords budgetrecords){
        log.info("更新数据：{}", budgetrecords);
        System.out.println("当前线程"+Thread.currentThread().getId());
        transactionService.update(budgetrecords);
        return Result.success();
    }

    @GetMapping()
    public Result selectByid(){
        log.info("查询数据：");
        System.out.println("当前线程"+Thread.currentThread().getId());
        Long id=BaseContext.getCurrentId();
        List<Budgetrecords> budgetrecordsList= transactionService.select(id);
        return Result.success(budgetrecordsList);
    }

    @PostMapping("/query")
    public Result query(@RequestBody Query query){
        System.out.println("当前线程"+Thread.currentThread().getId());
        log.info("查询数据：{}",query);
        List<Budgetrecords> budgetrecordsList= transactionService.query(query);
        log.info(budgetrecordsList.toString());
        return Result.success(budgetrecordsList);
    }
}
